package com.tang.managementdemo.service.Impl;

import com.tang.managementdemo.mapper.EmpMapper;
import com.tang.managementdemo.mapper.StuMapper;
import com.tang.managementdemo.pojo.JopOption;
import com.tang.managementdemo.pojo.StuOption;
import com.tang.managementdemo.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StuMapper StuMapper;
    @Override
    public JopOption findEmpJobData() {
        List<Map<String,Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new JopOption(jobList, dataList);
    }

    @Override
    public List<Map> findEmpGenderData() {
        System.out.println(empMapper.countGenderData());
        return empMapper.countGenderData();
    }

    @Override
    public List<Map> findStudentDegreeData() {
        return StuMapper.CountDegreeData();
    }

    @Override
    public StuOption findStudentCountData() {
       List<Map<Object, Object>> list= StuMapper.CountStudentData();
        list.forEach(dataMap -> {
            Object name = dataMap.get("pos");
            Object value = dataMap.get("total");
            System.out.println("Name: " + name + ", Value: " + value);
        });

        log.info("查询到学生统计数据：{}",list);
       List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
       List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();

        return new StuOption(clazzList, dataList);
    }


}
